package com.yao.mybatis.sqlsource;

import com.yao.mybatis.sqlnode.MixedSqlNode;

/**
 * 封装和处理带有${}和动态标签的sql
 *
 * @author Administrator
 */
public class DynamicSqlSource implements SqlSource {
    private MixedSqlNode mixedSqlNode;

    public DynamicSqlSource(MixedSqlNode mixedSqlNode) {
        this.mixedSqlNode = mixedSqlNode;
    }

    @Override
    public BoundSql getBoundSql(Object param) {
        //首先处理sqlnode
        DynamicContext context = new DynamicContext(param);
        mixedSqlNode.apply(context);
        SqlSourceParser sqlSourceParser = new SqlSourceParser();
        SqlSource sqlSource = sqlSourceParser.parse(context.getSql());
        return sqlSource.getBoundSql(param);
    }
}
